/**
 * Created by hxpeng on 2017/5/02.
 */
(function () {
    'use strict';

    angular.module('App.common')
        .filter('ageFilter', ageFilter);

    /**
     * 生日日期转年龄
     * @returns {Function}
     */
    function ageFilter() {
        function calculateAge(birthday) { // birthday is a date
            birthday = new Date(birthday);
            var ageDifMs = Date.now() - birthday.getTime();
            var ageDate = new Date(ageDifMs); // miliseconds from epoch
            return Math.abs(ageDate.getUTCFullYear() - 1970 + 1);
        }
        return function(birthdate) {
            return calculateAge(birthdate);
        };
    }

})();